$(document).ready(function() {	
	$("#frmLogin").validate({				
		onfocusout	: false,
		onkeyup		: false,
		rules: {
			pemail:{
				required 		: true
			},
			ppassword_htype: {
				required 		: true
			}
		},
		messages: {			
			pemail:{
				requiredField 	: 'Vui lòng nhập địa chỉ E-mail.'
			},
			ppassword_htype: {
				required 		: 'Vui lòng nhập mật khẩu đăng nhập.'
			}
		},		
		showErrors: function(errorMap, errorList) {
			var errors = this.numberOfInvalids(); 			
			var summary = "";
			$.each(errorList, function() {
				summary = this.message;
				$('#secErrorMessage').show();
				$('.errorMessage').show('slow');
				$('.errorMessage').html(summary);
				return false;
			});	
		},
		submitHandler: function(form) {	
			var strPass	= $('#ppassword_htype').val();				
			$.cookie('LOGIN_PASS', Base64.encode(Base64.encode(strPass)));		
			var postPass = MD5(MD5(strGeneralCode) + MD5(strPass));			
			$('#ppassword_header').val(postPass);			
			$('#ppassword_htype').val('');
			form.submit();
		}
	});
	$("#frmRegister").validate({				
		onfocusout	: false,
		onkeyup		: false,
		rules: {
			pfirstname:{
				required 			: true,
				minlength			: 2
			},
			plastname:{
				required 			: true,
				minlength			: 2
			},
			pemail:{
				required 			: true,
				email				: true
			},
			ppassword:{
				required			: true,
				minlength			: 8
			},
			ppassword_confirm:{
				required			: true,
				equalTo				: '#ppassword'
			},
			pgender: {
				required			: true
			},
			pyear: {
				birthdateRequired	: true,
				//validateBirthdate	: true
			},
			psrcid: {
				required			: true
			},
			pcaptcha: {
				required			: true,
				validateCaptcha		: true
			},
			ptos: {
				requiredCheck		: true
			}
		},
		messages: {
			pfirstname:{
				required 			: firstname_required,
				minlength			: firstname_minlength
			},
			plastname:{
				required 			: lastname_required,
				minlength			: lastname_minlength
			},
			pemail:{
				required 			: email_required,
				email				: email_invalid
			},
			ppassword:{
				required			: password_required,
				minlength			: password_minlength
			},
			ppassword_confirm:{
				required			: confirmpassword_required,
				equalTo				: confirmpassword_equalto
			},
			pgender: {
				required			: gender_required
			},
			pyear: {
				birthdateRequired	: birthdate_required,
				//validateBirthdate	: birthdate_invalid
			},
			psrcid: {
				required			: src_required
			},
			pcaptcha: {
				required			: captcha_required,
				validateCaptcha		: captcha_invalid
			},
			ptos: {
				requiredCheck		: tos_required
			}
		},		
		showErrors: function(errorMap, errorList) {
			var errors = this.numberOfInvalids(); 			
			var summary = "";
			$.each(errorList, function() {
				summary = this.message;				
				$('#secMessage').show();
				$('.errorMessage').show('slow');
				$('.errorMessage').html(summary);
				return false;
			});	
		}
	});	
	$.validator.addMethod('validateCaptcha', function() {
		var strCaptchaInput = $('#pcaptcha').val();
		return validateCaptcha(strCaptchaInput);
	});

	$.validator.addMethod('birthdateRequired', function(){		
		var year 	= $('#pyear').val();
		var month 	= $('#pmonth').val();
		var day 	= $('#pday').val();		
		if (year == "" || month == "" || day == "")
			return false;
		return true;
	});
	$.validator.addMethod('validateBirthdate', function(){											
		var year 	= $('#pyear').val();
		var month 	= $('#pmonth').val();
		var day 	= $('#pday').val();
		return checkDate(year,month,day);												
	});
	$.validator.addMethod('requiredCheck',function(){
		if(!$('#ptos').is(':checked')) {
			return false;
		}
		return true;
	});
});
showRegister = function() {
	$('#formLogin').hide();
	$('#formRegister').show();
	$('#secMessage').hide();
}
showLogin = function() {
	$('#formLogin').show();
	$('#formRegister').hide();
	$('#secErrorMessage').hide();
}